package com.nian.db.mysql.mycat.simple.controller;

import com.nian.common.model.ServerResponse;
import com.nian.db.mysql.mycat.simple.model.MyCatUser;
import com.nian.db.mysql.mycat.simple.service.IMyCatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用途：
 * 开发：zhangmj
 * 日期：2020/4/16 0016 17:53
 */
@RestController
@RequestMapping("myCatUser")
public class MyCatUserController {

    @Autowired
    IMyCatUserService iMyCatUserService;

    @PostMapping("find/{id}")
    public ServerResponse findById(@PathVariable("id") Long id) {
        MyCatUser info = iMyCatUserService.findById(id);
        return ServerResponse.createBySuccess(info);
    }

    @PostMapping("save")
    public ServerResponse save(@RequestBody MyCatUser model) {
        MyCatUser info = iMyCatUserService.save(model);
        return ServerResponse.createBySuccess(info);
    }

    @PostMapping("insert")
    public ServerResponse insert(@RequestBody MyCatUser model) {
        iMyCatUserService.insert(model);
        return ServerResponse.createBySuccess();
    }

    @PostMapping("saveAll")
    public ServerResponse saveAll(List<MyCatUser> list) {
        List<MyCatUser> l = iMyCatUserService.saveAll(list);
        return ServerResponse.createBySuccess(l);
    }

    @PostMapping("delete/{id}")
    public ServerResponse deleteById(@PathVariable("id") Long id) {
        iMyCatUserService.deleteById(id);
        return ServerResponse.createBySuccess();
    }
}
